home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.6 KB | 99 lines | [TEXT/CWIE] |
- // SequenceLoop.h
-
- #ifndef SequenceLoop_h
- #define SequenceLoop_h
-
- #ifndef SequenceLoop_h
- #include "SequenceLoop.h"
- #endif
- #ifndef Prepositions_h
- #include "Prepositions.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- /*
- SequenceLoops have three states:
- finished, where Null() and Finished() are both true;
- pointing to an element, where Null() and Finished() are both false;
- or pointing between adjacent elements, or between an element and the end,
- where Null() is true, but Finished() is false.
-
- The last state exists so that the loop can be in a sensible state when
- the element it was pointing to was removed, but a loop can also be put
- directly into that state. After ++ or -- a SequenceLoops will always be either
- at an element or finished.
- */
-
- template <class Head, class Node> class Sequence;
-
- template < class Head, class Node >
- class SequenceLoop
- {
- friend class Sequence<Head,Node>;
- typedef SequenceLoop<Head,Node> Loop;
-
- private:
- const Node *position;
- const Node *next;
- const Node *previous;
-
- const Head& head;
- Loop *nextLoop;
-
- bool finished;
-
- public:
- SequenceLoop( const Head& );
- SequenceLoop( const Head&, AtStart );
- SequenceLoop( const Head&, AtEnd );
- SequenceLoop( const Head&, Nowhere );
- SequenceLoop( const Head&, const Node& );
- SequenceLoop( const Head&, Before, const Node& );
- SequenceLoop( const Head&, After, const Node& );
- SequenceLoop( const Head&, BeforeStart );
- SequenceLoop( const Head&, AfterEnd );
- SequenceLoop( const Loop& );
-
- ~SequenceLoop();
-
- const Head& Owner() const { return head; }
-
- bool Finished() const { return finished; }
- bool Unfinished() const { return !finished; }
-
- void MoveToFinish();
- void MoveToFirst();
- void MoveToLast();
- void MoveTo( const Node& );
- void MoveBefore( const Node& );
- void MoveAfter( const Node& );
- void MoveBeforeFirst();
- void MoveAfterLast();
-
- void operator=( const Loop& );
-
- bool operator==( const Loop& ) const;
- bool operator!=( const Loop& r ) const { return !operator==( r ); }
-
- bool operator==( const Node& r ) const;
- bool operator!=( const Node& r ) const { return !operator==( r ); }
-
- bool Null() const { return position == 0; }
- const Node *Position() const { return position; }
-
- const Node *Next() const;
- const Node *Previous() const;
-
- const Node& operator*() const { Assert( position != 0 ); return *position; }
- const Node *operator->() const { Assert( position != 0 ); return position; }
-
- void operator++();
- void operator++(int) { operator++(); }
- void operator--();
- void operator--(int) { operator--(); }
- };
-
- #endif
-